package com.zicheng.util;

import java.io.File;

public class RenamePNGFiles_One {
    public static void main(String[] args) {
        // 请将此路径替换为实际包含 PNG 图片的文件夹路径
        String folderPath = "C:\\Users\\12464\\Desktop\\lemon玩家等级切图";
        File folder = new File(folderPath);

        if (folder.exists() && folder.isDirectory()) {
            File[] files = folder.listFiles((dir, name) -> name.toLowerCase().endsWith(".png") && name.matches("\\d+@2x.png"));
            if (files != null) {
                for (File file : files) {
                    String oldName = file.getName();
                    String newName = getNewName(oldName);
                    if (newName != null) {
                        File newFile = new File(folder, newName);
                        if (file.renameTo(newFile)) {
                            System.out.println("已将 " + oldName + " 重命名为 " + newName);
                        } else {
                            System.err.println("重命名 " + oldName + " 失败");
                        }
                    }
                }
            }
        }
    }

    private static String getNewName(String oldName) {
        int number = Integer.parseInt(oldName.replace("@2x.png", ""));
        if (number >= 11 && number <= 40) {
            return (number - 10) + ".png";
        } else if (number >= 51 && number <= 79) {
            return (number - 20) + ".png";
        }
        return null;
    }
}